package com.college.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.college.domain.User;
import com.college.facade.impl.UserCredentialFacadeImpl;

@Controller
public class UserCredentialsController {
	
	@Autowired
	private UserCredentialFacadeImpl userCredentialsFacade;
	
	@RequestMapping("userCredentials")
	public ModelAndView userCredentials(HttpServletRequest request,
	HttpServletResponse response) throws Exception {
		return new ModelAndView("userCredentials");

	}
	@RequestMapping("addUserCredentialsPage")
	public ModelAndView addUserCredentialsPage(HttpServletRequest request,
	HttpServletResponse response) throws Exception {
		return new ModelAndView("addUserCredentialsPage");

	}
	@RequestMapping("deleteUserCredentialsPage")
	public ModelAndView deleteUserCredentialsPage(HttpServletRequest request,
	HttpServletResponse response) throws Exception {
		return new ModelAndView("deleteUserCredentialsPage");

	}
	@RequestMapping("addUserCredentials")
	public ModelAndView addUserCredentials(HttpServletRequest request,
	HttpServletResponse response) throws Exception {
		
		User user = new User();
		if(userCredentialsFacade.addUserCredentials(request, user)){
			return new ModelAndView("userCredentials");

		}else{
			return new ModelAndView("userCredentials");

		}
		
		

	}
	@RequestMapping("deleteUserCredentials")
	public ModelAndView deleteUserCredentials(HttpServletRequest request,
	HttpServletResponse response) throws Exception {
		
		String userName = request.getParameter("userName");
		if(userCredentialsFacade.deleteUserCredentials(userName)){
			return new ModelAndView("userCredentials");

		}else{
			return new ModelAndView("userCredentials");

		}
		

	}

}
